package cn.iocoder.yudao.module.bpm.controller.admin.taggroupinfo;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.bpm.controller.admin.taggroupinfo.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.taggroupinfo.BpmTagGroupInfoDO;
import cn.iocoder.yudao.module.bpm.service.taggroupinfo.BpmTagGroupInfoService;

@Tag(name = "管理后台 - 标签组信息")
@RestController
@RequestMapping("/bpm/tag-group-info")
@Validated
public class BpmTagGroupInfoController {

    @Resource
    private BpmTagGroupInfoService tagGroupInfoService;

    @PostMapping("/create")
    @Operation(summary = "创建标签组信息")
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:create')")
    public CommonResult<Long> createTagGroupInfo(@Valid @RequestBody BpmTagGroupInfoSaveReqVO createReqVO) {
        return success(tagGroupInfoService.createTagGroupInfo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新标签组信息")
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:update')")
    public CommonResult<Boolean> updateTagGroupInfo(@Valid @RequestBody BpmTagGroupInfoSaveReqVO updateReqVO) {
        tagGroupInfoService.updateTagGroupInfo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除标签组信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:delete')")
    public CommonResult<Boolean> deleteTagGroupInfo(@RequestParam("id") Long id) {
        tagGroupInfoService.deleteTagGroupInfo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得标签组信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:query')")
    public CommonResult<BpmTagGroupInfoRespVO> getTagGroupInfo(@RequestParam("id") Long id) {
        BpmTagGroupInfoDO tagGroupInfo = tagGroupInfoService.getTagGroupInfo(id);
        return success(BeanUtils.toBean(tagGroupInfo, BpmTagGroupInfoRespVO.class));
    }

    @GetMapping("/all")
    @Operation(summary = "获取所有标签组信息")
    public CommonResult<List<BpmAllTagGroupInfoVO>> getAllTagGroupInfo(){
        List<BpmAllTagGroupInfoVO> result = tagGroupInfoService.getAllTagGroupInfo();
        return success(result);
    }

    @GetMapping("/page")
    @Operation(summary = "获得标签组信息分页")
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:query')")
    public CommonResult<PageResult<BpmTagGroupInfoRespVO>> getTagGroupInfoPage(@Valid BpmTagGroupInfoPageReqVO pageReqVO) {
        PageResult<BpmTagGroupInfoDO> pageResult = tagGroupInfoService.getTagGroupInfoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, BpmTagGroupInfoRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出标签组信息 Excel")
    @PreAuthorize("@ss.hasPermission('bpm:tag-group-info:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportTagGroupInfoExcel(@Valid BpmTagGroupInfoPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<BpmTagGroupInfoDO> list = tagGroupInfoService.getTagGroupInfoPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "标签组信息.xls", "数据", BpmTagGroupInfoRespVO.class,
                        BeanUtils.toBean(list, BpmTagGroupInfoRespVO.class));
    }

}